package eu.jpereira.trainings.designpatterns.creational.builder;

import eu.jpereira.trainings.designpatterns.creational.builder.json.JSONReportBody;
import eu.jpereira.trainings.designpatterns.creational.builder.model.ReportBody;

public class JSONReportBuilder implements iReportBuilder {

	 private JSONReportBody reportBody = new JSONReportBody();
	
	@Override
	public iReportBuilder setCustomerName(String name) {
		
		reportBody.addContent("sale:{customer:{");
		reportBody.addContent("name:\"");
		reportBody.addContent(name);
		
		return null;
	}

	@Override
	public iReportBuilder setCustomerPhone(String phone) {
		
		reportBody.addContent("\",phone:\"");
		reportBody.addContent(phone);
		reportBody.addContent("\"}");
		
		return null;
	}

	@Override
	public iReportBuilder makeItemList() {
		reportBody.addContent(",items:[");
		
		return null;
	}

	@Override
	public iReportBuilder addItem(String name, int quantity, double price, boolean hasNext) {

		reportBody.addContent("{name:\"");
		reportBody.addContent(name);
		reportBody.addContent("\",quantity:");
		reportBody.addContent(String.valueOf(quantity));
		reportBody.addContent(",price:");
		reportBody.addContent(String.valueOf(price));
		reportBody.addContent("}");
		
		if ( hasNext ) {
			reportBody.addContent(",");
		}
		else{
			reportBody.addContent("]}");
		}
		
		return null;
	}

	@Override
	public ReportBody getReportBody() {
		return this.reportBody;
	}

}
